import time

from hytest import *
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys

from lib.func_name import *
from lib.button import *
from lib.status_obj import *
from pom.page_teacher_op.homework_create_page import IFrameGreateHomework
from pom.page_teacher_op.question_info_page import QuestionInfoPage
from lib.share import *

class UI_A2004:
    name = 'UI-A2004'

    def teststeps(self):
        STEP(1, '获取习题状态信息')
        status_info = GSTORE['iframe_homework_create'].get_all_status()
        status_check_flag = 0
        for k, v in status_info.items():
            INFO(f'{k}:{v}')
            if int(v) != 0:
                status_check_flag += 1

        CHECK_POINT('查看所有题型数是否为0', status_check_flag == 0)


# 查看截图类测试
class UI_A2101:
    ddt_cases = [
        {
            'name': 'UI-A2101',
            'para': {
                'casename': 'UI-A2101',
                'button_list': [[button_按知识点, button_按章节]],
                'check_info': '确认目录是按章节排序',
            }
        },
        {
            'name': 'UI-A2123',
            'para': {
                'casename': 'UI-A2123',
                'button_list': [[button_按知识点]],
                'check_info': '确认目录是按知识点排序',
            }
        }
    ]

    def teardown(self):
        if GSTORE['teardown_button_list'] != []:
            GSTORE['iframe_homework_create'].click_buttons(GSTORE['teardown_button_list'])
            GSTORE['teardown_button_list'].clear()

    def teststeps(self):
        casename = self.para['casename']
        button_list = self.para['button_list']
        check_info = self.para['check_info']

        # obj1 = GSTORE['thome']
        # obj2 = GSTORE['thomework_create']
        obj3 = GSTORE['iframe_homework_create']
        # obj4 = GSTORE['thomework_created']

        flow1_dict = {
            'obj': obj3,
            func_click_buttons: button_list,
            func_screenshot: None
        }
        STEP(1, '获取截图')
        obj3.workflow(flow1_dict)

        if casename in ['UI-A2123']:
            GSTORE['teardown_button_list'] = [button_按章节]

        CHECK_POINT(f'需要人工查看截图，{check_info}', False)


# 查看题目信息类测试
class UI_A2102:
    ddt_cases = [
        {
            'name': 'UI-A2102',
            'para': {
                'casename': 'UI-A2102',
                'button_list': [[button_填空题, button_选择题]],
                'check_info': '选择题',
                'loc': QuestionInfoPage.loc_question_type
            }
        },
        {
            'name': 'UI-A2124',
            'para': {
                'casename': 'UI-A2124',
                'button_list': [[button_填空题, button_选择题]],
                'check_info': '选择题',
                'loc': QuestionInfoPage.loc_question_type
            }
        },
        {
            'name': 'UI-A2103',
            'para': {
                'casename': 'UI-A2103',
                'button_list': [[button_填空题]],
                'check_info': '填空题',
                'loc': QuestionInfoPage.loc_question_type
            }
        },
        {
            'name': 'UI-A2125',
            'para': {
                'casename': 'UI-A2125',
                'button_list': [[button_填空题]],
                'check_info': '填空题',
                'loc': QuestionInfoPage.loc_question_type
            }
        },
        {
            'name': 'UI-A2104',
            'para': {
                'casename': 'UI-A2104',
                'button_list': [[button_人教版, button_浙教版]],
                'check_info': '浙教版',
                'loc': QuestionInfoPage.loc_question_company
            }
        },
        {
            'name': 'UI-A2105',
            'para': {
                'casename': 'UI-A2105',
                'button_list': [[button_人教版]],
                'check_info': '人教版',
                'loc': QuestionInfoPage.loc_question_company
            }
        },
        {
            'name': 'UI-A2106',
            'para': {
                'casename': 'UI-A2106',
                'button_list': [[button_八年级, button_七年级]],
                'check_info': '七年级',
                'loc': QuestionInfoPage.loc_question_grade
            }
        },
        {
            'name': 'UI-A2107',
            'para': {
                'casename': 'UI-A2107',
                'button_list': [[button_八年级]],
                'check_info': '八年级',
                'loc': QuestionInfoPage.loc_question_grade
            }
        },
        {
            'name': 'UI-A2108',
            'para': {
                'casename': 'UI-A2108',
                'button_list': [[button_九年级]],
                'check_info': '九年级',
                'loc': QuestionInfoPage.loc_question_grade
            }
        },
        {
            'name': 'UI-A2110',
            'para': {
                'casename': 'UI-A2110',
                'button_list': [[button_高一]],
                'check_info': '高一',
                'loc': QuestionInfoPage.loc_question_grade
            }
        },
        {
            'name': 'UI-A2112',
            'para': {
                'casename': 'UI-A2112',
                'button_list': [[button_高二]],
                'check_info': '高二',
                'loc': QuestionInfoPage.loc_question_grade
            }
        },
        {
            'name': 'UI-A2114',
            'para': {
                'casename': 'UI-A2114',
                'button_list': [[button_高三]],
                'check_info': '高三',
                'loc': QuestionInfoPage.loc_question_grade
            }
        },
        {
            'name': 'UI-A2115',
            'para': {
                'casename': 'UI-A2115',
                'button_list': [[button_下册, button_上册]],
                'check_info': '上册',
                'loc': QuestionInfoPage.loc_question_book
            }
        },
        {
            'name': 'UI-A2117',
            'para': {
                'casename': 'UI-A2117',
                'button_list': [[button_下册]],
                'check_info': '下册',
                'loc': QuestionInfoPage.loc_question_book
            }
        },
        {
            'name': 'UI-A2118',
            'para': {
                'casename': 'UI-A2118',
                'button_list': [[button_中等, button_简单]],
                'check_info': '简单',
                'loc': QuestionInfoPage.loc_question_diff
            }
        },
        {
            'name': 'UI-A2126',
            'para': {
                'casename': 'UI-A2126',
                'button_list': [[button_中等, button_简单]],
                'check_info': '简单',
                'loc': QuestionInfoPage.loc_question_diff
            }
        },
        {
            'name': 'UI-A2119',
            'para': {
                'casename': 'UI-A2119',
                'button_list': [[button_简单, button_中等]],
                'check_info': '中等',
                'loc': QuestionInfoPage.loc_question_diff
            }
        },
        {
            'name': 'UI-A2127',
            'para': {
                'casename': 'UI-A2127',
                'button_list': [[button_简单, button_中等]],
                'check_info': '中等',
                'loc': QuestionInfoPage.loc_question_diff
            }
        },
        {
            'name': 'UI-A2120',
            'para': {
                'casename': 'UI-A2120',
                'button_list': [[button_简单, button_较难]],
                'check_info': '难',
                'loc': QuestionInfoPage.loc_question_diff
            }
        },
        {
            'name': 'UI-A2128',
            'para': {
                'casename': 'UI-A2128',
                'button_list': [[button_简单, button_较难]],
                'check_info': '难',
                'loc': QuestionInfoPage.loc_question_diff
            }
        },
        {
            'name': 'UI-A2122',
            'para': {
                'casename': 'UI-A2122',
                'button_list': [[button_九年级, button_我创建的]],
                'check_info': '测试用题目_我的创建',
                'loc': QuestionInfoPage.loc_question_content
            }
        },
        {
            'name': 'UI-A2130',
            'para': {
                'casename': 'UI-A2130',
                'button_list': [[button_我创建的]],
                'check_info': '测试用题目_我的创建',
                'loc': QuestionInfoPage.loc_question_content
            }
        },
        {
            'name': 'UI-A2301',
            'para': {
                'casename': 'UI-A2301',
                'button_list': [[button_七年级]],
                'check_info': '题目信息',
                'loc': QuestionInfoPage.loc_question_title
            }
        },
    ]

    def teardown(self):
        GSTORE['question_info'].close()
        GSTORE['question_info'].return_main_window(GSTORE['main_window'])
        GSTORE['iframe_homework_create'].jump()

        if GSTORE['teardown_button_list'] != []:
            GSTORE['iframe_homework_create'].click_buttons(GSTORE['teardown_button_list'])
            GSTORE['teardown_button_list'].clear()

    def teststeps(self):
        casename = self.para['casename']
        button_list = self.para['button_list']
        check_info = self.para['check_info']
        loc = self.para['loc']

        if casename in ['UI-A2124', 'UI-A2125', 'UI-A2126', 'UI-A2127', 'UI-A2128', 'UI-A2130']:
            button_list[0].insert(0, button_按知识点)

        # obj1 = GSTORE['thome']
        # obj2 = GSTORE['thomework_create']
        obj3 = GSTORE['iframe_homework_create']
        # obj4 = GSTORE['thomework_created']
        obj5 = GSTORE['question_info']

        flow_dict1 = {
            'obj': obj3,
            func_click_buttons: button_list,
            func_click_floor: {
                'loc_method': obj3.loc_question_method,
                'loc_value_input': obj3.loc_question_check_value,
                'index1': 1
            }
        }

        flow_dict2 = {
            'obj': obj5,
            func_jump_window: '题目查看'
        }

        flow_dict3 = {
            'obj': obj5,
            func_get_txt: loc
        }

        STEP(1, '点击选择题，并查看题目')
        obj3.workflow(flow_dict1)
        main_window = obj5.workflow(flow_dict2)
        GSTORE['main_window'] = main_window

        STEP(2, '获取题目信息')
        get_info_txt = obj5.workflow(flow_dict3)
        get_info_txt = get_info_txt.strip()
        INFO(f'获取结果:{get_info_txt}')

        if casename in ['UI-A2103', 'UI-A2125']:
            GSTORE['teardown_button_list'] = [button_选择题]
        if casename in ['UI-A2105']:
            GSTORE['teardown_button_list'] = [button_浙教版]
        if casename in ['UI-A2107', 'UI-A2108', 'UI-A2110', 'UI-A2112', 'UI-A2114']:
            GSTORE['teardown_button_list'] = [button_七年级]
        if casename in ['UI-A2117']:
            GSTORE['teardown_button_list'] = [button_上册]
        if casename in ['UI-A2118', 'UI-A2126']:
            GSTORE['teardown_button_list'] = [button_简单]
        if casename in ['UI-A2119', 'UI-A2127']:
            GSTORE['teardown_button_list'] = [button_中等]
        if casename in ['UI-A2120', 'UI-A2128']:
            GSTORE['teardown_button_list'] = [button_较难]
        if casename in ['UI-A2122']:
            GSTORE['teardown_button_list'] = [button_我创建的, button_七年级]
        if casename in ['UI-A2130']:
            GSTORE['teardown_button_list'] = [button_我创建的]

        if casename in ['UI-A2124', 'UI-A2125', 'UI-A2126', 'UI-A2127', 'UI-A2128', 'UI-A2130']:
            GSTORE['teardown_button_list'].append(button_按章节)

        CHECK_POINT(f'验证获取结果是否为： {check_info}', get_info_txt == check_info)


# 习题不存在类测试
class UI_A2109:
    ddt_cases = [
        {
            'name': 'UI-A2109',
            'para': {
                'casename': 'UI-A2109',
                'button': button_高一,
                'check_info': '该学科、年级、教材 还没有设置章节目录',
                'loc': IFrameGreateHomework.loc_pop_text,
                'before_button_list': [button_人教版]
            }
        },
        {
            'name': 'UI-A2111',
            'para': {
                'casename': 'UI-A2111',
                'button': button_高二,
                'check_info': '该学科、年级、教材 还没有设置章节目录',
                'loc': IFrameGreateHomework.loc_pop_text,
                'before_button_list': [button_人教版]
            }
        },
        {
            'name': 'UI-A2113',
            'para': {
                'casename': 'UI-A2113',
                'button': button_高三,
                'check_info': '该学科、年级、教材 还没有设置章节目录',
                'loc': IFrameGreateHomework.loc_pop_text,
                'before_button_list': [button_人教版]
            }
        },
        {
            'name': 'UI-A2116',
            'para': {
                'casename': 'UI-A2116',
                'button': button_高三,
                'check_info': '该学科、年级、教材 还没有设置章节目录',
                'loc': IFrameGreateHomework.loc_pop_text,
                'before_button_list': [button_下册]
            }
        },
        {
            'name': 'UI-A2121',
            'para': {
                'casename': 'UI-A2121',
                'button': button_我创建的,
                'check_info': '没有找到符合搜索条件的题目',
                'loc': IFrameGreateHomework.loc_no_search_text
            }
        },
        {
            'name': 'UI-A2129',
            'para': {
                'casename': 'UI-A2129',
                'button': button_我创建的,
                'check_info': '没有找到符合搜索条件的题目',
                'loc': IFrameGreateHomework.loc_no_search_text,
                'before_button_list': [button_按知识点, button_中等]
            }
        }
    ]

    def teardown(self):
        if 'no_pop' not in GSTORE['teardown_button_list']:
            GSTORE['iframe_homework_create'].click(GSTORE['iframe_homework_create'].loc_pop)
        else:
            GSTORE['teardown_button_list'].pop(-1)

        if GSTORE['teardown_button_list'] != []:
            GSTORE['iframe_homework_create'].click_buttons(GSTORE['teardown_button_list'])
            GSTORE['teardown_button_list'].clear()

    def teststeps(self):
        casename = self.para['casename']
        button = self.para['button']
        check_info = self.para['check_info']
        loc = self.para['loc']

        if 'before_button_list' in self.para:
            before_button_list = self.para['before_button_list']
        else:
            before_button_list = None

        # obj1 = GSTORE['thome']
        # obj2 = GSTORE['thomework_create']
        obj3 = GSTORE['iframe_homework_create']
        # obj4 = GSTORE['thomework_created']
        # obj5 = GSTORE['question_info']

        flow_dict1 = {
            'obj': obj3,
            func_click: obj3.button_dict[button],
            func_time_sleep: 1,
            func_get_txt: loc,
        }

        # if casename in ['UI-A2109','UI-A2111','UI-A2113']:
        #     obj3.click_button(button_人教版)
        # if casename in ['UI-A2116']:
        #     obj3.click_button(button_下册)

        if before_button_list:
            obj3.click_buttons(before_button_list)

        ret_txt = obj3.workflow(flow_dict1)
        INFO(f'弹出信息 ： {ret_txt}')

        if casename == 'UI-A2109':
            GSTORE['teardown_button_list'] = [button_七年级, button_浙教版]
        if casename == 'UI-A2111':
            GSTORE['teardown_button_list'] = [button_七年级, button_浙教版]
        if casename == 'UI-A2113':
            GSTORE['teardown_button_list'] = [button_七年级, button_浙教版]
        if casename == 'UI-A2116':
            GSTORE['teardown_button_list'] = [button_七年级, button_上册]
        if casename == 'UI-A2121':
            GSTORE['teardown_button_list'] = [button_我创建的, 'no_pop']
        if casename == 'UI-A2129':
            GSTORE['teardown_button_list'] = [button_我创建的, button_按章节, 'no_pop']

        CHECK_POINT('检验弹出信息', ret_txt == check_info)


# 阶层--查看题目信息类测试
class UI_A2201:
    ddt_cases = [
        {
            'name': 'UI-A2201',
            'para': {
                'casename': 'UI-A2201',
                'before_button_list': None,
                'floor_dict_list': [[
                    {
                        'loc_method': IFrameGreateHomework.loc_tree_chapter_method,
                        'loc_value_input': IFrameGreateHomework.loc_tree_chapter_value_list,
                        'index1': 2
                    },
                    {
                        'loc_method': IFrameGreateHomework.loc_tree_chapter_method,
                        'loc_value_input': IFrameGreateHomework.loc_tree_chapter_value_list,
                        'index1': 1
                    },
                ]],
                'check_info': '第一章 有理数',
                'loc': QuestionInfoPage.loc_question_chapter
            }
        },
        {
            'name': 'UI-A2202',
            'para': {
                'casename': 'UI-A2202',
                'before_button_list': None,
                'floor_dict_list': [[
                    {
                        'loc_method': IFrameGreateHomework.loc_tree_chapter_method,
                        'loc_value_input': IFrameGreateHomework.loc_tree_chapter_value_list,
                        'index1': 2
                    },
                    {
                        'loc_method': IFrameGreateHomework.loc_tree_chapter_method,
                        'loc_value_input': IFrameGreateHomework.loc_tree_chapter_value_list,
                        'index1': 1,
                        'index2': 1
                    },
                ]],
                'check_info': '1.1 从自然数到有理数',
                'loc': QuestionInfoPage.loc_question_chapter
            }
        },
        {
            'name': 'UI-A2203',
            'para': {
                'casename': 'UI-A2203',
                'before_button_list': None,
                'floor_dict_list': [[
                    {
                        'loc_method': IFrameGreateHomework.loc_tree_chapter_method,
                        'loc_value_input': IFrameGreateHomework.loc_tree_chapter_value_list,
                        'index1': 3,
                        'index2': 2
                    }
                ]],
                'check_info': '3.2 实数',
                'loc': QuestionInfoPage.loc_question_chapter
            }
        },
        {
            'name': 'UI-A2204',
            'para': {
                'casename': 'UI-A2204',
                'before_button_list': None,
                'floor_dict_list': [[
                    {
                        'loc_method': IFrameGreateHomework.loc_tree_chapter_method,
                        'loc_value_input': IFrameGreateHomework.loc_tree_chapter_value_list,
                        'index1': 6
                    },
                ]],
                'check_info': '第六章 图形的初步认识',
                'loc': QuestionInfoPage.loc_question_chapter
            }
        },
        {
            'name': 'UI-A2205',
            'para': {
                'casename': 'UI-A2205',
                'before_button_list': None,
                'floor_dict_list': [[
                    {
                        'loc_method': IFrameGreateHomework.loc_tree_chapter_method,
                        'loc_value_input': IFrameGreateHomework.loc_tree_chapter_value_list,
                        'index1': 6,
                        'index2': 1
                    },
                ]],
                'check_info': '6.1 几何图形',
                'loc': QuestionInfoPage.loc_question_chapter
            }
        },
        {
            'name': 'UI-A2206',
            'para': {
                'casename': 'UI-A2206',
                'before_button_list': None,
                'floor_dict_list': [[
                    {
                        'loc_method': IFrameGreateHomework.loc_tree_chapter_method,
                        'loc_value_input': IFrameGreateHomework.loc_tree_chapter_value_list,
                        'index1': 6,
                        'index2': 9
                    }
                ]],
                'check_info': '6.9 直线的相交',
                'loc': QuestionInfoPage.loc_question_chapter
            }
        },
        {
            'name': 'UI-A2208',
            'para': {
                'casename': 'UI-A2208',
                'before_button_list': [button_按知识点],
                'floor_dict_list': [[
                    {
                        'loc_method': IFrameGreateHomework.loc_tree_point_method,
                        'loc_value_input': IFrameGreateHomework.loc_tree_point_value_list,
                        'index1': 1,
                        'index2': 1,
                        'index3': 2
                    },
                ]],
                'check_info': '相反数',
                'loc': QuestionInfoPage.locs_question_point
            }
        },
        {
            'name': 'UI-A2210',
            'para': {
                'casename': 'UI-A2210',
                'before_button_list': [button_按知识点, button_简单],
                'floor_dict_list': [[
                    {
                        'loc_method': IFrameGreateHomework.loc_tree_point_method,
                        'loc_value_input': IFrameGreateHomework.loc_tree_point_value_list,
                        'index1': 1,
                        'index2': 1,
                        'index3': 2
                    },
                ]],
                'check_info': '相反数',
                'loc': QuestionInfoPage.locs_question_point
            }
        },
        {
            'name': 'UI-A2211',
            'para': {
                'casename': 'UI-A2211',
                'before_button_list': [button_按知识点, button_中等],
                'floor_dict_list': [[
                    {
                        'loc_method': IFrameGreateHomework.loc_tree_point_method,
                        'loc_value_input': IFrameGreateHomework.loc_tree_point_value_list,
                        'index1': 1,
                        'index2': 1,
                        'index3': 2
                    },
                ]],
                'check_info': '相反数',
                'loc': QuestionInfoPage.locs_question_point
            }
        },
        {
            'name': 'UI-A2212',
            'para': {
                'casename': 'UI-A2212',
                'before_button_list': [button_按知识点, button_较难],
                'floor_dict_list': [[
                    {
                        'loc_method': IFrameGreateHomework.loc_tree_point_method,
                        'loc_value_input': IFrameGreateHomework.loc_tree_point_value_list,
                        'index1': 1,
                        'index2': 1,
                        'index3': 2
                    },
                ]],
                'check_info': '相反数',
                'loc': QuestionInfoPage.locs_question_point
            }
        },
        {
            'name': 'UI-A2215',
            'para': {
                'casename': 'UI-A2215',
                'before_button_list': [button_按知识点, button_我创建的],
                'floor_dict_list': [[
                    {
                        'loc_method': IFrameGreateHomework.loc_tree_point_method,
                        'loc_value_input': IFrameGreateHomework.loc_tree_point_value_list,
                        'index1': 5
                    },
                ]],
                'check_info': '图形的变换',
                'loc': QuestionInfoPage.locs_question_point
            }
        },
        {
            'name': 'UI-A2302',
            'para': {
                'casename': 'UI-A2302',
                'before_button_list': [button_七年级],
                'floor_dict_list': [[
                    {
                        'loc_method': IFrameGreateHomework.loc_question_method,
                        'loc_value_input': IFrameGreateHomework.loc_question_check_value,
                        'index1': 3
                    }
                ]],
                'check_info': '题目信息',
                'loc': QuestionInfoPage.loc_question_title
            }
        },
    ]

    def teardown(self):
        GSTORE['question_info'].close()
        GSTORE['question_info'].return_main_window(GSTORE['main_window'])
        GSTORE['iframe_homework_create'].jump()

        if GSTORE['teardown_floor_dict'] != []:
            GSTORE['iframe_homework_create'].click_floor(**GSTORE['teardown_floor_dict'])
            GSTORE['teardown_floor_dict'].clear()

        if GSTORE['teardown_button_list'] != []:
            GSTORE['iframe_homework_create'].click_buttons(GSTORE['teardown_button_list'])
            GSTORE['teardown_button_list'].clear()

    def teststeps(self):
        casename = self.para['casename']
        before_button_list = self.para['before_button_list']
        floor_dict_list = self.para['floor_dict_list']
        check_info = self.para['check_info']
        loc = self.para['loc']

        # obj1 = GSTORE['thome']
        # obj2 = GSTORE['thomework_create']
        obj3 = GSTORE['iframe_homework_create']
        # obj4 = GSTORE['thomework_created']
        obj5 = GSTORE['question_info']

        GSTORE['teardown_floor_dict'] = floor_dict_list[0][-1]

        flow_dict1 = {
            'obj': obj3,
            func_click_floors: floor_dict_list,
            func_click_floor:
                {
                    'loc_method': obj3.loc_question_method,
                    'loc_value_input': obj3.loc_question_check_value,
                    'index1': 1
                }
        }

        if casename == 'UI-A2302':
            flow_dict1 = {
                'obj': obj3,
                func_click_floors: floor_dict_list,
            }
            GSTORE['teardown_floor_dict'] = []

        flow_dict2 = {
            'obj': obj5,
            func_jump_window: '题目查看'
        }

        flow_dict3 = {
            'obj': obj5,
            func_get_txt_or_txts: loc
        }

        if before_button_list:
            obj3.click_buttons(before_button_list)

        if casename in ['UI-A2208']:
            GSTORE['teardown_button_list'] = [button_按章节]
        if casename in ['UI-A2210']:
            GSTORE['teardown_button_list'] = [button_按章节, button_简单]
        if casename in ['UI-A2211']:
            GSTORE['teardown_button_list'] = [button_按章节, button_中等]
        if casename in ['UI-A2212']:
            GSTORE['teardown_button_list'] = [button_按章节, button_较难]
        if casename in ['UI-A2215']:
            GSTORE['teardown_button_list'] = [button_按章节, button_我创建的]

        STEP(1, '点击选择题，并查看题目')
        obj3.workflow(flow_dict1)
        main_window = obj5.workflow(flow_dict2)
        GSTORE['main_window'] = main_window

        STEP(2, '获取题目信息')
        get_info_txt = obj5.workflow(flow_dict3)
        INFO(f'获取结果:{get_info_txt}')
        if isinstance(get_info_txt, list):
            check_flag = 1
            for i in get_info_txt:
                if check_info in i:
                    check_flag = 0
                    break
            CHECK_POINT('查看题目是否属于该章节', check_flag == 0)
        else:
            get_info_txt = get_info_txt.strip()
            CHECK_POINT('查看题目是否属于该章节', check_info in get_info_txt)


# 阶层--习题不存在类测试
class UI_A2207:
    ddt_cases = [
        {
            'name': 'UI-A2207',
            'para': {
                'casename': 'UI-A2207',
                'before_button_list': [button_九年级, button_下册],
                'floor_dict_list': [[
                    {
                        'loc_method': IFrameGreateHomework.loc_tree_chapter_method,
                        'loc_value_input': IFrameGreateHomework.loc_tree_chapter_value_list,
                        'index1': 2,
                        'index2': 1
                    }
                ]],
                'check_info': '没有找到符合搜索条件的题目',
                'loc': IFrameGreateHomework.loc_no_search_text
            }
        },
        {
            'name': 'UI-A2209',
            'para': {
                'casename': 'UI-A2209',
                'before_button_list': [button_按知识点, button_填空题],
                'floor_dict_list': [[
                    {
                        'loc_method': IFrameGreateHomework.loc_tree_chapter_method,
                        'loc_value_input': IFrameGreateHomework.loc_tree_chapter_value_list,
                        'index1': 1,
                        'index2': 1,
                        'index3': 2,
                    }
                ]],
                'check_info': '没有找到符合搜索条件的题目',
                'loc': IFrameGreateHomework.loc_no_search_text
            }
        },
        {
            'name': 'UI-A2213',
            'para': {
                'casename': 'UI-A2213',
                'before_button_list': [button_按知识点, button_较难],
                'floor_dict_list': [[
                    {
                        'loc_method': IFrameGreateHomework.loc_tree_chapter_method,
                        'loc_value_input': IFrameGreateHomework.loc_tree_chapter_value_list,
                        'index1': 6,
                        'index2': 2,
                        'index3': 6,
                    }
                ]],
                'check_info': '没有找到符合搜索条件的题目',
                'loc': IFrameGreateHomework.loc_no_search_text
            }
        },
        {
            'name': 'UI-A2214',
            'para': {
                'casename': 'UI-A2214',
                'before_button_list': [button_按知识点, button_我创建的],
                'floor_dict_list': [[
                    {
                        'loc_method': IFrameGreateHomework.loc_tree_chapter_method,
                        'loc_value_input': IFrameGreateHomework.loc_tree_chapter_value_list,
                        'index1': 2
                    }
                ]],
                'check_info': '没有找到符合搜索条件的题目',
                'loc': IFrameGreateHomework.loc_no_search_text
            }
        },
    ]

    def teardown(self):
        if GSTORE['teardown_floor_dict'] != []:
            GSTORE['iframe_homework_create'].click_floor(**GSTORE['teardown_floor_dict'])
            GSTORE['teardown_floor_dict'].clear()

        if GSTORE['teardown_button_list'] != []:
            GSTORE['iframe_homework_create'].click_buttons(GSTORE['teardown_button_list'])
            GSTORE['teardown_button_list'].clear()

    def teststeps(self):
        casename = self.para['casename']
        before_button_list = self.para['before_button_list']
        floor_dict_list = self.para['floor_dict_list']
        check_info = self.para['check_info']
        loc = self.para['loc']

        # obj1 = GSTORE['thome']
        # obj2 = GSTORE['thomework_create']
        obj3 = GSTORE['iframe_homework_create']
        # obj4 = GSTORE['thomework_created']
        obj5 = GSTORE['question_info']

        flow_dict1 = {
            'obj': obj3,
            func_click_floors: floor_dict_list,
            func_get_txt: loc
        }

        if before_button_list:
            obj3.click_buttons(before_button_list)

        STEP(1, '点击选择题，并查看题目')
        ret_text = obj3.workflow(flow_dict1)
        INFO(ret_text)
        if casename in ['UI-A2207']:
            GSTORE['teardown_button_list'] = [button_上册, button_七年级]
        if casename in ['UI-A2209']:
            GSTORE['teardown_button_list'] = [button_选择题, button_按章节]
        if casename in ['UI-A2213']:
            GSTORE['teardown_button_list'] = [button_较难, button_按章节]
        if casename in ['UI-A2214']:
            GSTORE['teardown_button_list'] = [button_我创建的, button_按章节]

        GSTORE['teardown_floor_dict'] = floor_dict_list[0][-1]

        CHECK_POINT('检验弹出信息', check_info == ret_text)


class UI_A2303:
    ddt_cases = [
        {
            'name': 'UI-A2303',
            'para': [
                IFrameGreateHomework.loc_question_add_value.replace('index1', '1'),
                IFrameGreateHomework.loc_question_delete_value.replace('index1', '1')
            ]
        },
        {
            'name': 'UI-A2304',
            'para': [
                IFrameGreateHomework.loc_question_delete_value.replace('index1', '1'),
                IFrameGreateHomework.loc_question_add_value.replace('index1', '1')
            ]
        },
    ]

    # def teardown(self):
    #     if GSTORE['teardown_click']:
    #         IFrameGreateHomework.click(GSTORE['teardown_click'])

    def teststeps(self):
        # obj1 = GSTORE['thome']
        # obj2 = GSTORE['thomework_create']
        obj3 = GSTORE['iframe_homework_create']
        # obj4 = GSTORE['thomework_created']
        # obj5 = GSTORE['question_info']
        loc_value1, loc_value2 = self.para
        loc1 = (obj3.loc_question_method, loc_value1)
        loc2 = (obj3.loc_question_method, loc_value2)

        check_flag = 0
        if self.name == 'UI-A2304':
            obj3.click(loc2)
        try:
            obj3.click(loc1)
            check_flag += 1
            # INFO(check_flag)
        except:
            INFO('第一步执行失败')

        try:
            obj3.click(loc2)
            check_flag += 1
            # INFO(check_flag)
            if self.name == 'UI-A2304':
                obj3.click(loc1)
        except:
            INFO('第二步执行失败')

        CHECK_POINT('查看目标按钮是否发生改变', check_flag == 2)


# 单种习题状态取得
class UI_A2401:
    ddt_cases = [
        {
            'name': 'UI-A2401',
            'para': {
                'before_button_list': [button_简单],
                'loc_click': IFrameGreateHomework.loc_question_add_value,
                'loc_return': IFrameGreateHomework.loc_question_delete_value,
                'question_index_list': [1],
                'get_status_list': [status_选择题, status_选择题_简单],
                'change_count': 1
            }
        },
        {
            'name': 'UI-A2402',
            'para': {
                'before_button_list': [button_简单],
                'loc_click': IFrameGreateHomework.loc_question_add_value,
                'loc_return': IFrameGreateHomework.loc_question_delete_value,
                'question_index_list': [1, 10],
                'get_status_list': [status_选择题, status_选择题_简单],
                'change_count': 2
            }
        },
        {
            'name': 'UI-A2403',
            'para': {
                'before_button_list': [button_简单, button_填空题],
                'loc_click': IFrameGreateHomework.loc_question_add_value,
                'loc_return': IFrameGreateHomework.loc_question_delete_value,
                'question_index_list': [1],
                'get_status_list': [status_填空题, status_填空题_简单],
                'change_count': 1
            }
        },
        {
            'name': 'UI-A2404',
            'para': {
                'before_button_list': [button_简单, button_填空题],
                'loc_click': IFrameGreateHomework.loc_question_add_value,
                'loc_return': IFrameGreateHomework.loc_question_delete_value,
                'question_index_list': [1, 2],
                'get_status_list': [status_填空题, status_填空题_简单],
                'change_count': 2
            }
        },
        {
            'name': 'UI-A2405',
            'para': {
                'before_button_list': [button_中等],
                'loc_click': IFrameGreateHomework.loc_question_add_value,
                'loc_return': IFrameGreateHomework.loc_question_delete_value,
                'question_index_list': [1],
                'get_status_list': [status_选择题, status_选择题_中等],
                'change_count': 1
            }
        },
        {
            'name': 'UI-A2406',
            'para': {
                'before_button_list': [button_中等],
                'loc_click': IFrameGreateHomework.loc_question_add_value,
                'loc_return': IFrameGreateHomework.loc_question_delete_value,
                'question_index_list': [1, 10],
                'get_status_list': [status_选择题, status_选择题_中等],
                'change_count': 2
            }
        },
        {
            'name': 'UI-A2407',
            'para': {
                'before_button_list': [button_较难],
                'loc_click': IFrameGreateHomework.loc_question_add_value,
                'loc_return': IFrameGreateHomework.loc_question_delete_value,
                'question_index_list': [1],
                'get_status_list': [status_选择题, status_选择题_较难],
                'change_count': 1
            }
        },
        {
            'name': 'UI-A2408',
            'para': {
                'before_button_list': [button_较难],
                'loc_click': IFrameGreateHomework.loc_question_add_value,
                'loc_return': IFrameGreateHomework.loc_question_delete_value,
                'question_index_list': [1, 10],
                'get_status_list': [status_选择题, status_选择题_较难],
                'change_count': 2
            }
        },
        {
            'name': 'UI-A2409',
            'para': {
                'before_button_list': [button_简单],
                'loc_click': IFrameGreateHomework.loc_question_add_value,
                'loc_return': IFrameGreateHomework.loc_question_delete_value,
                'question_index_list': range(1, 11),
                'get_status_list': [status_选择题, status_选择题_简单],
                'change_count': 10
            }
        },
    ]

    def teardown(self):
        if GSTORE['teardown_floor_list'] != []:
            GSTORE['iframe_homework_create'].click_floors(GSTORE['teardown_floor_list'])
            GSTORE['teardown_floor_dict'].clear()

        if GSTORE['teardown_button_list'] != []:
            GSTORE['iframe_homework_create'].click_buttons(GSTORE['teardown_button_list'])
            GSTORE['teardown_button_list'].clear()

    def teststeps(self):
        before_button_list = self.para['before_button_list']
        loc_click = self.para['loc_click']
        loc_return = self.para['loc_return']
        question_index_list = self.para['question_index_list']
        get_status_list = self.para['get_status_list']
        change_count = self.para['change_count']

        # obj1 = GSTORE['thome']
        # obj2 = GSTORE['thomework_create']
        obj3 = GSTORE['iframe_homework_create']
        # obj4 = GSTORE['thomework_created']
        # obj5 = GSTORE['question_info']

        floor_list_op = []
        for i in question_index_list:
            floor_list_op.append({
                'loc_method': obj3.loc_question_method,
                'loc_value_input': loc_click,
                'index1': i,
            })

        floor_list_ret = []
        for i in question_index_list:
            floor_list_ret.append({
                'loc_method': obj3.loc_question_method,
                'loc_value_input': loc_return,
                'index1': i,
            })

        flow_dict1 = {
            'obj': obj3,
            func_click_buttons: [before_button_list],
            func_get_status_append_to_list: [get_status_list]

        }

        flow_dict2 = {
            'obj': obj3,
            func_click_floors: [floor_list_op],
            func_get_status_append_to_list: [get_status_list]
        }

        STEP(1, '获取操作前的目标题型状态')
        res_list1 = obj3.workflow(flow_dict1)

        STEP(2, '操作后获取目标题的型状态')
        res_list2 = obj3.workflow(flow_dict2)

        CHECK_POINT('查看操作前后的结果数量是否一直', len(res_list1) == len(res_list2))

        if self.name in ['UI-A2401', 'UI-A2402',
                         'UI-A2405', 'UI-A2406',
                         'UI-A2407', 'UI-A2407',
                         'UI-A2409',
                         ]:
            GSTORE['teardown_button_list'] = before_button_list
        if self.name in ['UI-A2403', 'UI-A2404']:
            before_button_list.remove(button_填空题)
            before_button_list.append(button_选择题)
            GSTORE['teardown_button_list'] = before_button_list

        GSTORE['teardown_floor_list'] = floor_list_ret

        for i in range(len(res_list1)):
            INFO(f'操作前题目数量  {get_status_list[i]} 操作前:{res_list1[i]}  操作后:{res_list2[i]}')
            check_count = int(res_list2[i]) - int(res_list1[i])
            CHECK_POINT(f'题数增加: {change_count}', check_count == change_count)


class UI_A2410:
    ddt_cases = [
        {'name': 'UI-A2410',
         'para': {'floor_list': [{
             'loc_method': IFrameGreateHomework.loc_question_method,
             'loc_value_input': IFrameGreateHomework.loc_question_add_value,
             'index1': 1
         },
             {
                 'loc_method': IFrameGreateHomework.loc_question_method,
                 'loc_value_input': IFrameGreateHomework.loc_question_add_value,
                 'index1': 10
             },
         ],
             'floor_return_list': [{
                 'loc_method': IFrameGreateHomework.loc_question_method,
                 'loc_value_input': IFrameGreateHomework.loc_question_delete_value,
                 'index1': 1
             },
                 {
                     'loc_method': IFrameGreateHomework.loc_question_method,
                     'loc_value_input': IFrameGreateHomework.loc_question_delete_value,
                     'index1': 10
                 },
             ],
         },
         },
        {'name': 'UI-A2411',
         'para': {'floor_list': [{
             'loc_method': IFrameGreateHomework.loc_question_method,
             'loc_value_input': IFrameGreateHomework.loc_question_add_value,
             'index1': 1
         }],
             'floor_return_list': [{
                 'loc_method': IFrameGreateHomework.loc_question_method,
                 'loc_value_input': IFrameGreateHomework.loc_question_delete_value,
                 'index1': 1
             }, ],
         },
         },
    ]

    def teststeps(self):
        floor_list = self.para['floor_list']
        floor_return_list = self.para['floor_return_list']

        # obj1 = GSTORE['thome']
        # obj2 = GSTORE['thomework_create']
        obj3 = GSTORE['iframe_homework_create']
        # obj4 = GSTORE['thomework_created']
        # obj5 = GSTORE['question_info']

        flow_dict1 = {'obj': obj3,
                      func_click_button: button_简单,
                      func_click_floors: [floor_list], }

        flow_dict2 = {'obj': obj3,
                      func_click_button: button_中等,
                      func_click_floors: [floor_list], }

        flow_dict3 = {'obj': obj3,
                      func_click_button: button_较难,
                      func_click_floors: [floor_list]}

        flow_dict4 = {'obj': obj3,
                      func_click_buttons: [[button_简单, button_填空题]],
                      func_click_floors: [floor_list]}

        STEP(1, '操作前获取状态信息')
        status_before = obj3.get_all_status()
        INFO(f'操作前  {status_before}')

        STEP(2, '执行操作并获取操作后的状态信息')
        obj3.workflow(flow_dict1)
        obj3.workflow(flow_dict2)
        obj3.workflow(flow_dict3)
        if self.name == 'UI-A2411':
            obj3.workflow(flow_dict4)

        status_after = obj3.get_all_status()
        INFO(f'操作后  {status_after}')

        flow_return_dict1 = {'obj': obj3,
                             func_click_button: button_简单,
                             func_click_floors: [floor_return_list], }

        flow_return_dict2 = {'obj': obj3,
                             func_click_button: button_中等,
                             func_click_floors: [floor_return_list], }

        flow_return_dict3 = {'obj': obj3,
                             func_click_button: button_较难,
                             func_click_floors: [floor_return_list]}

        flow_return_dict4 = {'obj': obj3,
                             func_click_buttons: [[button_简单, button_填空题]],
                             func_click_floors: [floor_return_list]}

        if self.name == 'UI-A2411':
            obj3.click_button(button_选择题)
        obj3.workflow(flow_return_dict1)
        obj3.workflow(flow_return_dict2)
        obj3.workflow(flow_return_dict3)
        if self.name == 'UI-A2411':
            obj3.workflow(flow_return_dict4)

        if self.name == 'UI-A2411':
            CHECK_POINT('检查题目状态', int(status_after['选择题']) == 3 and
                        int(status_after['选择题-简单']) == 1 and
                        int(status_after['选择题-中等']) == 1 and
                        int(status_after['选择题-较难']) == 1 and
                        int(status_after['填空题']) == 1 and
                        int(status_after['填空题-简单']) == 1)
            obj3.click_button(button_选择题)
        elif self.name == 'UI-A2410':
            CHECK_POINT('检查题目状态', int(status_after['选择题']) == 6 and
                        int(status_after['选择题-简单']) == 2 and
                        int(status_after['选择题-中等']) == 2 and
                        int(status_after['选择题-较难']) == 2 and
                        int(status_after['填空题']) == 0)


# 本页全加入、本页全移除
class UI_A2501:
    ddt_cases = [
        {'name': 'UI-A2501',
         'para': [button_本页全加入, button_本页全移除]},
        {'name': 'UI-A2502',
         'para': [button_本页全加入, button_下一页, button_本页全加入, button_上一页, button_本页全移除]},
        {'name': 'UI-A2503',
         'para': [button_下一页, button_本页全加入, button_上一页, button_本页全移除]},
        {'name': 'UI-A2504',
         'para': [button_本页全加入]},
        {'name': 'UI-A2505',
         'para': [button_本页全加入]},
    ]

    def teardown(self):
        GSTORE['iframe_homework_create'].click_buttons(GSTORE['teardoen_button_list'])

    def teststeps(self):
        button_list = self.para

        # obj1 = GSTORE['thome']
        # obj2 = GSTORE['thomework_create']
        obj3 = GSTORE['iframe_homework_create']
        # obj4 = GSTORE['thomework_created']
        # obj5 = GSTORE['question_info']

        if self.name in ['UI-A2503', 'UI-A2505', ]:
            obj3.click_floor(obj3.loc_question_method, obj3.loc_question_add_value, index1=1)

        STEP(1, '取得题目状态')
        obj3.click_buttons(button_list)
        status_op = obj3.get_all_status()

        if self.name == 'UI-A2501':
            GSTORE['teardoen_button_list'] = [button_七年级]
            CHECK_POINT('检查题目状态是否为0', int(status_op['选择题']) == 0 and
                        int(status_op['填空题']) == 0)
        if self.name in ['UI-A2502', 'UI-A2503']:
            GSTORE['teardoen_button_list'] = [button_下一页, button_本页全移除, button_上一页]
            # 测试追加
            INFO(status_op['选择题'])
            INFO(status_op['选择题-简单'])
            INFO(status_op['选择题-中等'])
            INFO(status_op['填空题'])
            CHECK_POINT('检查题目状态', int(status_op['选择题']) == 10 and
                        int(status_op['选择题-简单']) == 10 and
                        int(status_op['选择题-中等']) == 0 and
                        int(status_op['填空题']) == 0)

        if self.name in ['UI-A2504', 'UI-A2505']:
            GSTORE['teardoen_button_list'] = [button_本页全移除]
            # 测试追加
            INFO(status_op['选择题'])
            INFO(status_op['选择题-简单'])
            INFO(status_op['选择题-中等'])
            INFO(status_op['填空题'])
            CHECK_POINT('检查题目状态', int(status_op['选择题']) == 10 and
                        int(status_op['选择题-简单']) == 10 and
                        int(status_op['选择题-中等']) == 0 and
                        int(status_op['填空题']) == 0)


# 清空试题篮
class UI_A2506:
    ddt_cases = [
        {'name': 'UI-A2506', 'para': ''},
        {'name': 'UI-A2507', 'para': ''},
        {'name': 'UI-A2508', 'para': ''},
        {'name': 'UI-A2509', 'para': ''},
    ]

    def teardown(self):
        GSTORE['iframe_homework_create'].click_floor(GSTORE['iframe_homework_create'].loc_question_method,
                                                     GSTORE['iframe_homework_create'].loc_question_add_value,
                                                     index1=1)
        GSTORE['iframe_homework_create'].click_buttons(button_本页全移除)

    def teststeps(self):
        # obj1 = GSTORE['thome']
        # obj2 = GSTORE['thomework_create']
        obj3 = GSTORE['iframe_homework_create']
        # obj4 = GSTORE['thomework_created']
        # obj5 = GSTORE['question_info']

        STEP(1, '前置准备')
        if self.name == 'UI-A2506':
            obj3.click_floor(obj3.loc_question_method, obj3.loc_question_add_value, index1=1)
        if self.name == 'UI-A2507':
            obj3.click_button(button_本页全加入)
        if self.name == 'UI-A2508':
            obj3.click_buttons([button_本页全加入, button_下一页, button_本页全加入])
        if self.name == 'UI-A2509':
            obj3.click_floor(obj3.loc_question_method, obj3.loc_question_add_value, index1=1)
            obj3.click_button(button_下一页)
            obj3.click_floor(obj3.loc_question_method, obj3.loc_question_add_value, index1=1)

        STEP(2, '清空试题篮')
        obj3.click_button(button_清空试题篮)
        time.sleep(0.5)  # 不可删除强制等待
        obj3.driver.implicitly_wait(1)
        try:
            obj3.locate(obj3.loc_status_choice)
            CHECK_POINT('状态栏已消失', False)
        except:
            CHECK_POINT('状态栏已消失', True)
        obj3.driver.implicitly_wait(5)


# 选择习题 ---- 确定
class UI_A2601:
    ddt_cases = [
        {'name': 'UI-A2601', 'para': ''},
        {'name': 'UI-A2602', 'para': ''},
        {'name': 'UI-A2603', 'para': ''},
        {'name': 'UI-A2604', 'para': ''},
    ]

    def teardown(self):
        # GSTORE['thomework_create'].select_question()
        # GSTORE['iframe_homework_create'].jump()
        # GSTORE['iframe_homework_create'].click_button(button_清空试题篮)
        # GSTORE['iframe_homework_create'].click_buttob(button_确定)
        #
        # GSTORE['iframe_homework_create'].click_floor(GSTORE['iframe_homework_create'].loc_question_method,
        #                                              GSTORE['iframe_homework_create'].loc_question_add_value,
        #                                              index1=1)
        # GSTORE['iframe_homework_create'].click_button(button_本页全移除)
        GSTORE['thomework_create'].click(GSTORE['thomework_create'].loc_questions_op_delete,
                                         flag_all=True)
        GSTORE['thomework_create'].select_question()
        GSTORE['iframe_homework_create'].jump()

    def teststeps(self):
        # obj1 = GSTORE['thome']
        obj2 = GSTORE['thomework_create']
        obj3 = GSTORE['iframe_homework_create']
        # obj4 = GSTORE['thomework_created']
        # obj5 = GSTORE['question_info']

        STEP(1, '试题选择')
        if self.name in ['UI-A2601']:
            obj3.click_floor(obj3.loc_question_method,
                             obj3.loc_question_add_value,
                             index1=1)
        if self.name in ['UI-A2602']:
            obj3.click_floor(obj3.loc_question_method,
                             obj3.loc_question_add_value,
                             index1=10)
        if self.name in ['UI-A2603']:
            obj3.click_floors([
                {'loc_method': obj3.loc_question_method,
                 'loc_value_input': obj3.loc_question_add_value,
                 'index1': 1},
                {'loc_method': obj3.loc_question_method,
                 'loc_value_input': obj3.loc_question_add_value,
                 'index1': 5},
                {'loc_method': obj3.loc_question_method,
                 'loc_value_input': obj3.loc_question_add_value,
                 'index1': 10}])
        if self.name in ['UI-A2604']:
            obj3.click_buttons([button_本页全加入, button_下一页, button_本页全加入, button_下一页, button_本页全加入])

        STEP(2, '确定添加作业')
        obj3.click_button(button_确定)
        obj3.leave_iframe()

        question_count = len(obj2.locates(obj2.loc_selected_questions))

        if self.name in ['UI-A2601', 'UI-A2602']:
            CHECK_POINT('已加入1道题', question_count == 1)
        if self.name in ['UI-A2603']:
            CHECK_POINT('已加入3道题', question_count == 3)
        if self.name in ['UI-A2604']:
            CHECK_POINT('已加入30道题', question_count == 30)


# 选择习题 ---- 取消1
class UI_A2605:
    ddt_cases = [
        {'name': 'UI-A2605', 'para': ''},
        {'name': 'UI-A2606', 'para': ''},
        {'name': 'UI-A2607', 'para': ''},
        {'name': 'UI-A2608', 'para': ''},
    ]

    def teardown(self):
        GSTORE['thomework_create'].select_question()
        GSTORE['iframe_homework_create'].jump()

    def teststeps(self):
        # obj1 = GSTORE['thome']
        obj2 = GSTORE['thomework_create']
        obj3 = GSTORE['iframe_homework_create']
        # obj4 = GSTORE['thomework_created']
        # obj5 = GSTORE['question_info']

        STEP(1, '试题选择')
        if self.name in ['UI-A2605']:
            obj3.click_floor(obj3.loc_question_method,
                             obj3.loc_question_add_value,
                             index1=1)
        if self.name in ['UI-A2606']:
            obj3.click_floor(obj3.loc_question_method,
                             obj3.loc_question_add_value,
                             index1=10)
        if self.name in ['UI-A2607']:
            obj3.click_floors([
                {'loc_method': obj3.loc_question_method,
                 'loc_value_input': obj3.loc_question_add_value,
                 'index1': 1},
                {'loc_method': obj3.loc_question_method,
                 'loc_value_input': obj3.loc_question_add_value,
                 'index1': 5},
                {'loc_method': obj3.loc_question_method,
                 'loc_value_input': obj3.loc_question_add_value,
                 'index1': 10}])
        if self.name in ['UI-A2608']:
            obj3.click_buttons([button_本页全加入, button_下一页, button_本页全加入, button_下一页, button_本页全加入])

        STEP(2, '取消添加')
        obj3.click_button(button_取消)
        obj3.leave_iframe()

        obj2.driver.implicitly_wait(1)
        element_list = obj2.locates(obj2.loc_selected_questions)
        if element_list:
            CHECK_POINT('选择习题被清除', False)
        else:
            CHECK_POINT('选择习题被清除', True)
        obj2.driver.implicitly_wait(5)


# 选择习题 ---- 取消2
class UI_A2609:
    ddt_cases = [
        {'name': 'UI-A2609', 'para': ''},
        {'name': 'UI-A2610', 'para': ''},
        {'name': 'UI-A2611', 'para': ''},
        {'name': 'UI-A2612', 'para': ''},
    ]

    def teststeps(self):
        # obj1 = GSTORE['thome']
        obj2 = GSTORE['thomework_create']
        obj3 = GSTORE['iframe_homework_create']
        # obj4 = GSTORE['thomework_created']
        # obj5 = GSTORE['question_info']

        STEP(1, '试题选择')
        if self.name in ['UI-A2609']:
            obj3.click_floor(obj3.loc_question_method,
                             obj3.loc_question_add_value,
                             index1=1)
        if self.name in ['UI-A2610']:
            obj3.click_floor(obj3.loc_question_method,
                             obj3.loc_question_add_value,
                             index1=10)
        if self.name in ['UI-A2611']:
            obj3.click_floors([
                {'loc_method': obj3.loc_question_method,
                 'loc_value_input': obj3.loc_question_add_value,
                 'index1': 1},
                {'loc_method': obj3.loc_question_method,
                 'loc_value_input': obj3.loc_question_add_value,
                 'index1': 5},
                {'loc_method': obj3.loc_question_method,
                 'loc_value_input': obj3.loc_question_add_value,
                 'index1': 10}])
        if self.name in ['UI-A2612']:
            obj3.click_buttons([button_本页全加入, button_下一页, button_本页全加入, button_下一页, button_本页全加入])

        STEP(2, '取消添加')
        obj3.click_button(button_取消)
        obj3.leave_iframe()

        obj2.select_question()
        obj3.jump()

        choice_count = int(obj3.get_status_choice())
        blank_count = int(obj3.get_status_blank())

        CHECK_POINT('试题的选择已被清空', choice_count == 0 and
                    blank_count == 0)


class UI_A3101:
    ddt_cases = [
        {'name': 'UI-A3101', 'para': ''},
        {'name': 'UI-A3102', 'para': ''},
        {'name': 'UI-A3103', 'para': ''},
        {'name': 'UI-A3104', 'para': ''},
        {'name': 'UI-A3105', 'para': ''},
        {'name': 'UI-A3106', 'para': ''},
        {'name': 'UI-A3107', 'para': ''},
        {'name': 'UI-A3108', 'para': ''},
        {'name': 'UI-A3109', 'para': ''},
    ]

    def setup(self):
        GSTORE['iframe_homework_create'].click_floor(GSTORE['iframe_homework_create'].loc_question_method,
                                                     GSTORE['iframe_homework_create'].loc_question_add_value,
                                                     index1=1)
        GSTORE['iframe_homework_create'].click_button(button_确定)
        GSTORE['iframe_homework_create'].leave_iframe()
        GSTORE['thomework_create'].select_question()
        GSTORE['iframe_homework_create'].jump()

    def teardown(self):
        GSTORE['thomework_create'].select_question()
        GSTORE['iframe_homework_create'].jump()
        GSTORE['iframe_homework_create'].click_button(button_清空试题篮)
        time.sleep(0.5)
        GSTORE['iframe_homework_create'].click_floor(GSTORE['iframe_homework_create'].loc_question_method,
                                                     GSTORE['iframe_homework_create'].loc_question_add_value,
                                                     index1=1)
        GSTORE['iframe_homework_create'].click_button(button_本页全移除)

    def teststeps(self):
        # obj1 = GSTORE['thome']
        obj2 = GSTORE['thomework_create']
        obj3 = GSTORE['iframe_homework_create']
        # obj4 = GSTORE['thomework_created']
        # obj5 = GSTORE['question_info']

        if self.name == 'UI-A3101':
            obj3.click_floor(obj3.loc_question_method,
                             obj3.loc_question_add_value,
                             index1=2)
        if self.name == 'UI-A3102':
            obj3.click_button(button_本页全加入)
        if self.name == 'UI-A3103':
            obj3.click_button(button_下一页)
            obj3.click_button(button_本页全加入)
        if self.name == 'UI-A3104':
            obj3.click_floor(obj3.loc_question_method,
                             obj3.loc_question_delete_value,
                             index1=1)
        if self.name == 'UI-A3105' or self.name == 'UI-A3106':
            obj3.click_button(button_本页全移除)
        if self.name == 'UI-A3107':
            obj3.click_button(button_清空试题篮)
            time.sleep(0.5)
        if self.name == 'UI-A3108':
            obj3.click_buttons([button_下一页, button_清空试题篮])
            time.sleep(0.5)

        obj3.click_button(button_确定)
        obj3.leave_iframe()
        obj3.driver.implicitly_wait(1)
        question_count = len(obj2.locates(obj2.loc_selected_questions))
        obj3.driver.implicitly_wait(5)
        INFO(f'{question_count}道习题被加入')

        if self.name in ['UI-A3101']:
            CHECK_POINT('2道习题被加入', question_count == 2)
        if self.name == 'UI-A3102':
            CHECK_POINT('本页习题被加入', question_count == 10)
        if self.name == 'UI-A3103':
            CHECK_POINT('本页习题被加入', question_count == 11)
        if self.name in ['UI-A3104', 'UI-A3105', 'UI-A3106', 'UI-A3107', 'UI-A3108']:
            CHECK_POINT('已选习题被删除', question_count == 0)


class UI_A3109:
    name = 'UI-A3109'

    def setup(self):
        GSTORE['iframe_homework_create'].click_buttons(
            [button_本页全加入, button_下一页, button_本页全加入, button_下一页, button_本页全加入])
        GSTORE['iframe_homework_create'].click_button(button_确定)
        GSTORE['iframe_homework_create'].leave_iframe()
        GSTORE['thomework_create'].select_question()
        GSTORE['iframe_homework_create'].jump()

    def teardown(self):
        GSTORE['thomework_create'].select_question()
        GSTORE['iframe_homework_create'].jump()
        GSTORE['iframe_homework_create'].click_button(button_清空试题篮)
        time.sleep(0.5)
        GSTORE['iframe_homework_create'].click_floor(GSTORE['iframe_homework_create'].loc_question_method,
                                                     GSTORE['iframe_homework_create'].loc_question_add_value,
                                                     index1=1)
        GSTORE['iframe_homework_create'].click_button(button_本页全移除)

    def teststeps(self):
        # obj1 = GSTORE['thome']
        obj2 = GSTORE['thomework_create']
        obj3 = GSTORE['iframe_homework_create']
        # obj4 = GSTORE['thomework_created']
        # obj5 = GSTORE['question_info']

        obj3.click_button(button_清空试题篮)
        time.sleep(0.5)
        obj3.click_button(button_确定)
        obj3.leave_iframe()
        obj3.driver.implicitly_wait(1)
        question_count = len(obj2.locates(obj2.loc_selected_questions))
        obj3.driver.implicitly_wait(5)
        INFO(f'{question_count}道习题被加入')

        CHECK_POINT('已选习题被删除', question_count == 0)


class UI_A3201:
    ddt_cases = [
        {'name': 'UI-A3201', 'para': ''},
        {'name': 'UI-A3301', 'para': ''},
    ]

    def setup(self):
        GSTORE['iframe_homework_create'].click_floor(GSTORE['iframe_homework_create'].loc_question_method,
                                                     GSTORE['iframe_homework_create'].loc_question_add_value,
                                                     index1=1)
        GSTORE['iframe_homework_create'].click_button(button_确定)
        GSTORE['iframe_homework_create'].leave_iframe()

    def teardown(self):
        GSTORE['thomework_create'].select_question()
        GSTORE['iframe_homework_create'].jump()
        GSTORE['iframe_homework_create'].click_button(button_清空试题篮)
        time.sleep(0.5)
        GSTORE['iframe_homework_create'].click_floor(GSTORE['iframe_homework_create'].loc_question_method,
                                                     GSTORE['iframe_homework_create'].loc_question_add_value,
                                                     index1=1)
        GSTORE['iframe_homework_create'].click_button(button_本页全移除)

    def teststeps(self):
        # obj1 = GSTORE['thome']
        obj2 = GSTORE['thomework_create']
        obj3 = GSTORE['iframe_homework_create']
        # obj4 = GSTORE['thomework_created']
        # obj5 = GSTORE['question_info']

        if self.name == 'UI-A3201':
            obj2.click(obj2.loc_all_need_process)
        if self.name == 'UI-A3301':
            obj2.locates(obj2.loc_checkbox_need_process)[0].click()

        obj2.screenshot()
        CHECK_POINT('需要人工查看截图', False)


class UI_A3202:
    name = 'UI-A3202'

    def setup(self):
        GSTORE['iframe_homework_create'].click_buttons(
            [button_本页全加入, button_下一页, button_本页全加入, button_下一页, button_本页全加入])
        GSTORE['iframe_homework_create'].click_button(button_确定)
        GSTORE['iframe_homework_create'].leave_iframe()

    def teardown(self):
        ac_t = ActionChains(GSTORE['thomework_create'].driver)
        for i in range(100):
            ac_t.key_down(Keys.PAGE_UP)
            ac_t.key_up(Keys.PAGE_UP)
            ac_t.perform()
        time.sleep(0.5)
        # GSTORE['thomework_create'].select_question()
        # GSTORE['iframe_homework_create'].jump()
        # GSTORE['iframe_homework_create'].click_button(button_清空试题篮)
        # time.sleep(0.5)
        # GSTORE['iframe_homework_create'].click_floor(GSTORE['iframe_homework_create'].loc_question_method,
        #                                              GSTORE['iframe_homework_create'].loc_question_add_value,
        #                                              index1=1)
        # GSTORE['iframe_homework_create'].click_button(button_本页全移除)

        GSTORE['thomework_create'].click(GSTORE['thomework_create'].loc_questions_op_delete,
                                         flag_all=True)
        GSTORE['thomework_create'].select_question()
        GSTORE['iframe_homework_create'].jump()

    def teststeps(self):
        # obj1 = GSTORE['thome']
        obj2 = GSTORE['thomework_create']
        obj3 = GSTORE['iframe_homework_create']
        # obj4 = GSTORE['thomework_created']
        # obj5 = GSTORE['question_info']

        obj2.click(obj2.loc_all_need_process)
        ac = ActionChains(obj2.driver)
        for i in range(100):
            if i <= 5:
                obj2.screenshot()

            ac.key_down(Keys.PAGE_DOWN)
            ac.key_up(Keys.PAGE_DOWN)
            ac.perform()

            if i == 99:
                obj2.screenshot()

        CHECK_POINT('需要人工查看截图', False)


class UI_A3302:
    name = 'UI-A3302'

    def setup(self):
        GSTORE['iframe_homework_create'].click_floor(GSTORE['iframe_homework_create'].loc_question_method,
                                                     GSTORE['iframe_homework_create'].loc_question_add_value,
                                                     index1=1)
        GSTORE['iframe_homework_create'].click_floor(GSTORE['iframe_homework_create'].loc_question_method,
                                                     GSTORE['iframe_homework_create'].loc_question_add_value,
                                                     index1=2)
        GSTORE['iframe_homework_create'].click_floor(GSTORE['iframe_homework_create'].loc_question_method,
                                                     GSTORE['iframe_homework_create'].loc_question_add_value,
                                                     index1=3)
        GSTORE['iframe_homework_create'].click_button(button_确定)
        GSTORE['iframe_homework_create'].leave_iframe()

    def teardown(self):
        ac_t = ActionChains(GSTORE['thomework_create'].driver)
        for i in range(3):
            ac_t.key_down(Keys.PAGE_UP)
            ac_t.key_up(Keys.PAGE_UP)
            ac_t.perform()
        time.sleep(0.5)
        #
        # GSTORE['thomework_create'].select_question()
        # GSTORE['iframe_homework_create'].jump()
        # GSTORE['iframe_homework_create'].click_button(button_清空试题篮)
        # time.sleep(0.5)
        # GSTORE['iframe_homework_create'].click_floor(GSTORE['iframe_homework_create'].loc_question_method,
        #                                              GSTORE['iframe_homework_create'].loc_question_add_value,
        #                                              index1=1)
        # GSTORE['iframe_homework_create'].click_button(button_本页全移除)
        GSTORE['thomework_create'].click(GSTORE['thomework_create'].loc_questions_op_delete,
                                         flag_all=True)
        GSTORE['thomework_create'].select_question()
        GSTORE['iframe_homework_create'].jump()

    def teststeps(self):
        # obj1 = GSTORE['thome']
        obj2 = GSTORE['thomework_create']
        obj3 = GSTORE['iframe_homework_create']
        # obj4 = GSTORE['thomework_created']
        # obj5 = GSTORE['question_info']

        for i in obj2.locates(obj2.loc_checkbox_need_process):
            i.click()

        ac = ActionChains(obj2.driver)

        for i in range(2):
            ac.key_down(Keys.PAGE_DOWN)
            ac.key_up(Keys.PAGE_DOWN)
            ac.perform()
            obj2.screenshot()

        CHECK_POINT('需要人工查看截图', False)


class UI_A3401:
    name = 'UI-A3401'

    def setup(self):
        GSTORE['iframe_homework_create'].click_floor(GSTORE['iframe_homework_create'].loc_question_method,
                                                     GSTORE['iframe_homework_create'].loc_question_add_value,
                                                     index1=1)
        GSTORE['iframe_homework_create'].click_button(button_确定)
        GSTORE['iframe_homework_create'].leave_iframe()

    def teardown(self):
        GSTORE['thomework_create'].select_question()
        GSTORE['iframe_homework_create'].jump()
        GSTORE['iframe_homework_create'].click_button(button_清空试题篮)
        time.sleep(0.5)
        GSTORE['iframe_homework_create'].click_floor(GSTORE['iframe_homework_create'].loc_question_method,
                                                     GSTORE['iframe_homework_create'].loc_question_add_value,
                                                     index1=1)
        GSTORE['iframe_homework_create'].click_button(button_本页全移除)

    def teststeps(self):
        # obj1 = GSTORE['thome']
        obj2 = GSTORE['thomework_create']
        # obj3 = GSTORE['iframe_homework_create']
        # obj4 = GSTORE['thomework_created']
        obj5 = GSTORE['question_info']
        loc_check = (css, ".div-search-result-one .div-search-result-one-button-bar div label:nth-of-type(1)")
        loc_question_content1 = (css, ".div-search-result-one-text p:nth-of-type(1)")
        loc_question_content2 = (css, "#Question_content_text>p:nth-of-type(1)")

        obj2.click(loc_check)
        question_content1 = obj2.get_txt(loc_question_content1)
        main_window = obj2.jump_window('题目查看')
        question_content2 = obj2.get_txt(loc_question_content2)
        INFO(question_content1)
        INFO(question_content2)
        obj5.close()
        obj2.return_main_window(main_window)

        CHECK_POINT('查看题目信息是否一致', question_content1 == question_content2)


class UI_A3402:
    ddt_cases = [
        {'name': 'UI-A3402', 'para': ''},
        {'name': 'UI-A3403', 'para': ''},
        {'name': 'UI-A3404', 'para': ''},
    ]

    def setup(self):
        GSTORE['iframe_homework_create'].click_buttons([button_本页全加入, button_确定])
        GSTORE['iframe_homework_create'].leave_iframe()

    def teardown(self):
        GSTORE['thomework_create'].select_question()
        GSTORE['iframe_homework_create'].jump()
        GSTORE['iframe_homework_create'].click_button(button_清空试题篮)
        time.sleep(0.5)
        GSTORE['iframe_homework_create'].click_floor(GSTORE['iframe_homework_create'].loc_question_method,
                                                     GSTORE['iframe_homework_create'].loc_question_add_value,
                                                     index1=1)
        GSTORE['iframe_homework_create'].click_button(button_本页全移除)

    def teststeps(self):
        # obj1 = GSTORE['thome']
        obj2 = GSTORE['thomework_create']
        # obj3 = GSTORE['iframe_homework_create']
        # obj4 = GSTORE['thomework_created']
        # obj5 = GSTORE['question_info']
        loc_delete = (css, ".div-search-result-one .div-search-result-one-button-bar div label:nth-of-type(2)")
        loc_question2_up = (xpath, "//*[@class='div-search-result-one-text']/../../*[2]/*[3]/div/*[3]")
        loc_question1_down = (xpath, "//*[@class='div-search-result-one-text']/../../*[1]/*[3]/div/*[4]")

        if self.name == 'UI-A3402':
            obj2.locates(loc_delete)[0].click()
            quextion_count = len(obj2.locates(obj2.loc_selected_questions))
            CHECK_POINT('查看题目是否被删除', quextion_count == 9)
        else:
            obj2.screenshot()
            if self.name == 'UI-A3403':
                obj2.click(loc_question2_up)
            if self.name == 'UI-A3404':
                obj2.click(loc_question1_down)
            obj2.screenshot()
            CHECK_POINT('需要人工查看截图', False)
